//
//  ABStatusForwardCell.swift
//  microblog
//
//  Created by 安波 on 15/11/2.
//  Copyright © 2015年 anbo. All rights reserved.
//

import UIKit
import FFAutoLayout

class ABStatusForwardCell: ABStatusCell {
    
    // MARK: - 属性
    // 添加 override关键字,实现属性监视器,先调用父类的属性监视器,在调用子类的属性监视器
    /// 覆盖父类的模型属性
    override var status: ABStatus? {
        didSet {
            // 设置转发微博label的内容
            let name = status?.retweeted_status?.user?.name ?? "名称为空"
            let text = status?.retweeted_status?.text ?? "内容为空"
            forwardLabel.text = "@\(name): \(text)"
        }
    }
    
    // MARK: 准备UI（覆盖父类的方法）需要去掉父类中私有的private
    override func prepareUI() {
        super.prepareUI()
        
        // 添加子控件
//        contentView.addSubview(bkgButton)
        // 修改添加位置，将bkgButton 插入到 配图下面
        contentView.insertSubview(bkgButton, belowSubview: pictureView)
        contentView.addSubview(forwardLabel)
        
        // 添加约束
        // 背景按钮 左上角
        bkgButton.ff_AlignVertical(ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -statusCellMargin, y: statusCellMargin))
        // 背景按钮 右下角
        bkgButton.ff_AlignVertical(ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        // 被转发的微博内容
        forwardLabel.ff_AlignInner(ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint(x: statusCellMargin, y: statusCellMargin))
        // 内容的宽度约束
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.width() - 2 * statusCellMargin))
        
        // 微博配图
        let con = pictureView.ff_AlignVertical(ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 0, height: 0), offset: CGPoint(x: 0, y: statusCellMargin))
        pictureViewWidthCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Width)
        pictureViewHeightCon = pictureView.ff_Constraint(con, attribute: NSLayoutAttribute.Height)
        
    }
    

    // MARK: - 懒加载
    /// 灰色背景Button
    private lazy var bkgButton: UIButton = {
        // 创建按钮
        let button = UIButton()
        
        // 设置背景
        button.backgroundColor = UIColor.lightGrayColor()
        
        // 返回
        return button
        
    }()
    
    /// 被转发微博的内容label
    private lazy var forwardLabel: UILabel = {
        // 创建label
        let label = UILabel()
        
        // 设置属性
        label.textColor = UIColor(white: 0.9, alpha: 1)
        label.numberOfLines = 0
        
        // 设置测试文字内容
//        label.text = "父类的转发微博的配图约束，需要在一个cell来继承statusCell，添加上配图的约束。"
        
        // 返回label
        return label
        
    }()

}
